package com.erik.lin.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

/**
 * Created by Erik on 2017/4/17.
 */
@Component
@Aspect
public class TimeHandler {

    private Logger LOG = LoggerFactory.getLogger(TimeHandler.class);

    @Pointcut("execution(* com.erik.lin.controller.ApiPermitController.*(..))")
    public void aspect() {

    }

    @Around("aspect()")
    public void printTime(ProceedingJoinPoint pjp) throws Throwable {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        Object retVal = pjp.proceed();
        stopWatch.stop();
        LOG.warn("{}---耗时---{}", pjp.getSignature().toString(), stopWatch.getTotalTimeMillis());
    }
}
